package com.zhiwang.xiaoqu.ui

import android.graphics.Color
import android.os.Bundle
import android.view.View
import com.zhiwang.xiaoqu.R
import com.zhiwang.xiaoqu.bus.LoginEvent
import com.zhiwang.xiaoqu.di.annotation.Injectable
import com.zhiwang.xiaoqu.di.component.DaggerUserComponent
import com.zhiwang.xiaoqu.di.module.AutoDisposeModule
import com.zhiwang.xiaoqu.ktextension.setImmersive
import com.zhiwang.xiaoqu.mvp.presenter.UserPresenter
import kotlinx.android.synthetic.main.activity_phone_login.*
import org.greenrobot.eventbus.EventBus
import suicideAfterTransition
import javax.inject.Inject

class PhoneLoginActivity : BaseActivity(), Injectable {


    @Inject
    lateinit var userPresenter: UserPresenter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.setImmersive(Color.TRANSPARENT, true)
        setContentView(R.layout.activity_phone_login)
    }

    fun login(view: View) {

        val phone = phone_number.text.toString()
        val pwd = password.text.toString()

        userPresenter.loginByPhone(phone, pwd, "xxx", ::onLogin, ::onError)
    }

    private fun onLogin() {
        EventBus.getDefault().post(LoginEvent())
        suicideAfterTransition()
    }
}
